package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.dao.CustomerReturnListGoodsDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao customerDao;

    @Override
    public Map<String, Object> list(Integer page, Integer rows, String customerName) {
        Map<String, Object> result=new HashMap<>();
        List<Customer>  list=customerDao.list((page-1)*rows,rows,customerName);
        result.put("rows",list);
        result.put("total",list.size());
        return result;
    }

    @Override
    public void save(Customer customer) {
        if(StringUtils.isEmpty(customer.getCustomerId())){
            //增加
            customerDao.insert(customer);
        }else {
            //修改+
            customerDao.update(customer);
        }
    }

    @Override
    public void delete(String ids) {
        List<String> ts = Arrays.asList(ids.split(","));
        customerDao.delete(ts);
    }
}
